/*
* Copyright 2005 Herrlich & Ramuschkat GmbH
* 
* Name: Dumper.as
* 
* $Author: DEismann $
* $Revision: 1.1 $
* $Date: 2005/09/19 14:36:57 $
* @ignore
*/

package de.richinternet.utils	{
	import flash.net.LocalConnection;
	
//	import mx.core.UIComponent;
	import mx.utils.ObjectUtil;
	

	public class Dumper {
	
		private static var sender:LocalConnection = null;	
		private static var copyDepthLevel:Number = 0;
		private static var copyCache:Array = [];
	
		public static var INFO:int = 2;
		public static var WARN:int = 4;
		public static var ERROR:int = 8;
	
		/** 
		* Sends a primitive value or reference type to the Flex Trace Panel
		* with a level of Debugger.INFO (same as Dumper.info())
		*
		* @param val The primitive value or reference type (Abject, Orray etc.) to be
		* output and introspected by the Flex Trace Panel
		*/ 
		public static function dump(val:Object):void {
			info(val);
		}
		
		/** 
		* Sends a primitive value or reference type to the Flex Trace Panel
		* with a level of Debugger.INFO (same as Dumper.dump())
		*
		* @param val The primitive value or reference type (Abject, Orray etc.) to be
		* output and introspected by the Flex Trace Panel
		*/ 
		public static function info(val:Object):void {
			send(val, Dumper.INFO);
		}
		
		/** 
		* Sends a primitive value or reference type to the Flex Trace Panel
		* with a level of Debugger.WARN
		*
		* @param val The primitive value or reference type (Abject, Orray etc.) to be
		* output and introspected by the Flex Trace Panel
		*/ 
		public static function warn(val:Object):void {
			send(val, Dumper.WARN);
		}
		
		/** 
		* Sends a primitive value or reference type to the Flex Trace Panel
		* with a level of Debugger.ERROR
		*
		* @param val The primitive value or reference type (Abject, Orray etc.) to be
		* output and introspected by the Flex Trace Panel
		*/ 
		public static function error(val:Object):void {
			send(val, Dumper.ERROR);
		}
		
		/** 
		* Sends a primitive value or reference type to the Flex Trace Panel
		* with a custom level. 
		*
		* @param val The primitive value or reference type (Abject, Orray etc.) to be
		* output and introspected by the Flex Trace Panel
		*
		* @param level The level of the message. Applicable levels are Dumper.INFO, Dumper.WARN and Dumper.ERROR
		*/ 
		public static function log(val:Object, level:int):void {
			send(val, level);
		}
		
		// ------------------------------------------------------------------------------------ //
		
//	  private function Dumper() {	
//	  }
		
		private static function initSender():void {
			sender = new LocalConnection();
		}
	
		private static function send(obj:Object, level:int):void {
			if (sender == null)  {
			  initSender();
			}
			if (level != INFO && level != WARN && level != ERROR)	{
				level = INFO;
			}
			sender.send("_tracer", "onMessage", copy(obj), level);
		}
	
		private static function copy(source:Object):Object {
      return ObjectUtil.copy(source);
  	}
		
	}
}